// pages/singer/singer.js
const { get_singerList } = require("../../utils/ajax")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        typeList1:["热门",..."ABCDEFGHIGKLMNOPQRSTUVWXYZ".split("")],
        index1:0,
        typeList2:["全部","华语男","华语女","华语组合","日韩男","日韩女","日韩组合","欧美男","欧美女","欧美组合","其他"],
        index2:0,
        singerList:[],
        page:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getSingerList()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        this.data.page++
        this.getSingerList()
    },

    changeType1(e){
        this.setData({
            index1:e.currentTarget.dataset.index,
            singerList:[],
            page:1
        },()=>{
            this.getSingerList()
        })
    },
    changeType2(e){
        this.setData({
            index2:e.currentTarget.dataset.index,
            singerList:[],
            page:1
        },()=>{
            this.getSingerList()
        })
    },
    getSingerList(){
        let option = {
            category:this.data.index2,
            pn:this.data.page,
            rn:8
        }
        this.data.index1 && (option.prefix = this.data.typeList1[this.data.index1])
        get_singerList(option).then(res =>{
            this.setData({
                singerList:[...this.data.singerList,...res.data.artistList]
            })
        })
    }
})